package com.banquetmanagementsystem.mapper;

import com.banquetmanagementsystem.pojo.entity.BanquetApplication;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 86176
 */
@Mapper
public interface BanquetApplicationMapper {
    /**
     * 查看所有申请
     *
     * @return 返回所有申请
     */
    @Select("SELECT ID, USER_ID, BANQUET_TYPE_ID, NUMBER_OF_PEOPLE, PROCESSING_ADDRESS, BANQUET_DESCRIBE, START_TIME, END_TIME, CREATE_DATE, IS_PASS_THROUGH FROM banquet_application")
    List<BanquetApplication> getAllBanquetApplications();

    /**
     * 根据申请ID查看
     *
     * @param id 申请ID
     * @return 返回申请
     */
    @Select("SELECT ID, USER_ID, BANQUET_TYPE_ID, NUMBER_OF_PEOPLE, PROCESSING_ADDRESS, BANQUET_DESCRIBE, START_TIME, END_TIME, CREATE_DATE, IS_PASS_THROUGH FROM banquet_application WHERE ID=#{id}")
    BanquetApplication getBanquetApplicationById(Integer id);

    /**
     * 根据用户ID获取用户的所有申请表
     *
     * @param userId 用户ID
     * @return 该用户的所有申请
     */
    @Select("SELECT ID, USER_ID, BANQUET_TYPE_ID, NUMBER_OF_PEOPLE, PROCESSING_ADDRESS, BANQUET_DESCRIBE, START_TIME, END_TIME, CREATE_DATE, IS_PASS_THROUGH FROM banquet_application WHERE USER_ID=#{userId}")
    List<BanquetApplication> getBanquetApplicationByUserId(Integer userId);

    /**
     * 创建申请
     *
     * @param banquetApplication 申请信息
     * @return 受影响条数
     */
    @Insert("INSERT INTO banquet_application(user_id,banquet_type_id,number_of_people,processing_address,BANQUET_DESCRIBE,start_time,end_time,IS_PASS_THROUGH) VALUES (#{userId},#{banqueTypeId},#{numberOfPeople},#{processingAddress},#{banqueDescribe},#{startTime},#{endTime},#{isPassThrough})")
    Integer insertBanquetApplication(BanquetApplication banquetApplication);

    /**
     * 根据id通过申请
     *
     * @param id 申请ID
     * @return 受影响的行数
     */
    @Update("UPDATE banquet_application SET IS_PASS_THROUGH = true WHERE ID = #{id}")
    Integer passThroughBanquetApplication(Integer id);
}
